package dao.impl;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.orm.hibernate3.support.HibernateDaoSupport;

import dao.IBookDao;

import entity.Book;

public class BookDao extends HibernateDaoSupport implements IBookDao {
	private final Logger log = LoggerFactory.getLogger(BookDao.class);

	/*
	 * (non-Javadoc)
	 * 
	 * @see dao.IBookDao#saveBook(entity.Book)
	 */
	public void saveBook(Book transientInstance) {
		log.debug("saving Book instance");
		try {
			getHibernateTemplate().save(transientInstance);
			log.debug("save successful");
		} catch (RuntimeException re) {
			log.error("save failed", re);
			throw re;
		}
	}

	@Override
	public Book findById(int id) {
		log.debug("getting Book instance with id: " + id);
		try {
			Book instance = (Book) getHibernateTemplate().get(
					"entity.Book", id);
			return instance;
		} catch (RuntimeException re) {
			log.error("get failed", re);
			throw re;
		}
	}
}
